//
//  UUNotificationUtility.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 06/03/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUNotificationUtility.h"
#import <UUFoundation/NSObject+CopyObjectValue.h>

#import "UUNotificationNewsCell.h"
#import "UUNotificationCommonCell.h"

#import "UUIntentOrderDetailVC.h"
#import <UUFoundation/UUFormBaseVC.h>
#import "UUProductEditVC.h"
#import "UUCarEditVC.h"
#import "UUWalletWithdrawDetailVC.h"
#import "UUOrderDetailVC.h"

@implementation UUNotificationUtility

static NSDictionary <NSString *, Class> *targetVCClassMapper;

+ (void)initialize {
    if (self == [UUNotificationUtility class]) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            targetVCClassMapper = @{
                                    @"1" : [UUIntentOrderDetailVC class],
                                    @"2" : [UUOrderDetailVC class],
                                    @"3" : [UUOrderDetailVC class],
                                    @"4" : [UUOrderDetailVC class],
                                    @"6" : [UUOrderDetailVC class],
                                    @"7" : [UUWalletWithdrawDetailVC class],
                                    @"8" : [UUWalletWithdrawDetailVC class],
                                    @"9" : [UUProductEditVC class],
                                    @"10" : [UUProductEditVC class],
                                    @"11" : [UUCarEditVC class],
                                    @"12" : [UUCarEditVC class],
                                    @"14" : [UUHybridWebVC class],
                                    };
        });
    }
}

+ (Class)notificationCellForContentType:(UUNotificationContentType)contentType {
    switch (contentType) {
        case UUNotificationContentTypeIntentPlatform:
            return [UUNotificationNewsCell class];
        default:
            return [UUNotificationCommonCell class];
    }
}

+ (UIViewController *)targetVCWithNotification:(UUNotificationModel *)notification {
    UUBaseVC *targetVC = nil;

    Class targetClass = [targetVCClassMapper objectForKey:[NSString stringWithFormat:@"%ld", notification.content.type]];
    if (targetClass != nil) {
        targetVC = [targetClass instanceOfAppropriate];
        [targetVC copyObjectValueWithSourceObject:notification.content];
    }
    
    return targetVC;

}

@end
